package com.coding.basic.linklist;

/**
 * 用双向链表实现LRU算法
 * 
 * @author liuxin
 */
public class LRUPageFrame {
	private static class Node {
		Node prev;
		Node next;
		int pageNum;

		Node() {
		}
	}

	private int capacity;
	private Node first;// 链表头
	private Node last;// 链表尾

	public LRUPageFrame(int capacity) {
		this.capacity = capacity;
	}

	/**
	 * 获取缓存中对象
	 * 
	 * @param key
	 * @return
	 */
	public void access(int pageNum) {
	}

	@Override
	public String toString() {
		StringBuilder buffer = new StringBuilder();
		Node node = first;
		while (node != null) {
			buffer.append(node.pageNum);

			node = node.next;
			if (node != null) {
				buffer.append(",");
			}
		}

		return buffer.toString();
	}
}
